package tester.outcome.person;

import messages.observer.EventCollectionMessage;
import state.Globals;
import state.group.events.BaseEvent;
import state.group.events.EventCollection;
import state.group.events.EventType;
import state.person.events.DestinationEvent;
import tester.outcome.BaseEventOutcome;

/**
 * This class looks for a person going out of an elevator message
 * @author Caleb Chan
 *
 */
public class PersonGoingOutOutcome extends BaseEventOutcome {

	private String person;
	
	/**
	 * PersonGoingOutOutcome constructor
	 * @param startTime The start time of the outcome
	 * @param person The name of the person to be checked against
	 */
	public PersonGoingOutOutcome(long startTime, String person) {
		super(startTime);
		this.person = person;
	}

	@Override
	public boolean checkOutcome(EventCollectionMessage message) {
		
		EventCollection collection = message.getEvents();
		
		for(BaseEvent e : collection){
			Globals.getLogger().log("Message Received is : " + e.getEventType());
			// Checks if a the event is a destination event
			if (e.getEventType() == EventType.DestinationEvent){
				DestinationEvent rE = (DestinationEvent)e;
				Globals.getLogger().log("------------ GoingOutEvent -----------");
				Globals.getLogger().log("rE Person Name -> " + rE.getPersonId().toString());
				Globals.getLogger().log("Person Name -> " + person);
				// Checks if the persons name are equal
				if (rE.getPersonId().toString().equals(person)){
					isCompleted = true;
				}
			}
		}
		
		return isCompleted;
	}

	/**
	 * This method returns the name of person being check against
	 * @return Returns the name of the person
	 */
	public String getPerson(){
		return person;
	}
	
	@Override
	public String getOutcomeName() {
		return "PersonGoingOutOutcome";
	}

	@Override
	public BaseEventOutcome copy() {
		return new PersonGoingOutOutcome(0, person);
	}

	@Override
	public String getOutcomeChecksStr() {
		return getOutcomeName() + " Name -> " + person;
	}
}
